package com.costmary.spper.util;

import com.costmary.spper.model.Weather;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.util.logging.Logger;

/**
 * Created by IntelliJ IDEA.
 * User: sen
 * Date: 2010-9-18
 * Time: 22:01:01
 * To change this template use File | Settings | File Templates.
 */
public class WeatherFormatter {
    private static Logger log = Logger.getLogger("WeatherFormatter.class");
    public String format(Weather weather) throws Exception {
        log.info("Formatting Weather Dates");
        Reader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("output.vm"));
        VelocityContext context = new VelocityContext();
        context.put("weather",weather);
        StringWriter writer = new StringWriter();
        Velocity.evaluate(context, writer, "", reader);
        return writer.toString();

    }
}
